﻿using System;

using Common;
using Maticsoft.DBUtility;
using System.Data.OleDb;

namespace Habito.Admini
{
	public partial class Login : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected override void OnInit(EventArgs e)
		{
			//if (Request.QueryString["IsLogin"] == "1")
			//{
			//    string username = Request.QueryString["name"];
			//    string pwd = Request.QueryString["pwd"];
			//    string sql = "select count(0) from admin where username = @username and pwd= @pwd";
			//    OleDbParameter[] parameters = {
			//        new OleDbParameter("@username", OleDbType.VarChar,60),
			//        new OleDbParameter("@pwd", OleDbType.VarChar,255)};
			//    parameters[0].Value = username;
			//    parameters[1].Value = pwd;
			//    object obj = DataOperate.ExecuteScalar(PubConstant.ConnectionString, sql, parameters);
			//    if (obj == null)
			//    {
			//        Response.Write("0");
			//        Response.End();
			//    }
			//    else
			//    {
			//        int exists = Convert.ToInt32(obj.ToString());
			//        bool result = exists > 0;
			//        Session["username"] = username;
			//        Session.Timeout = 5;
			//        Ticket.UserName = username;
			//        Ticket.LoginTime = DateTime.Now.ToShortTimeString();
			//        Response.Write(result ? "1" : "0");
			//        Response.End();
			//    }
			//}
			//base.OnInit(e);
		}

		protected void Unnamed1_Click(object sender, EventArgs e)
		{
			string username = this.username.Value;
			string pwd = this.pwd.Value;
			string sql = "select count(0) from admin where username = @username and pwd= @pwd";
			OleDbParameter[] parameters = {
					new OleDbParameter("@username", OleDbType.VarChar,60),
					new OleDbParameter("@pwd", OleDbType.VarChar,255)};
			parameters[0].Value = username;
			parameters[1].Value = pwd;
			object obj = DataOperate.ExecuteScalar(PubConstant.ConnectionString, sql, parameters);
			if (obj == null)
			{
				Response.Redirect("Login.aspx");
			}
			else
			{
				int aa = Convert.ToInt32(obj.ToString());
				if (aa == 0)
				{
					Response.Redirect("Login.aspx");
				}
				Session["username"] = username;
				Session.Timeout = 15;
				Ticket.UserName = username;
				Ticket.LoginTime = DateTime.Now.ToShortTimeString();
				Response.Redirect("Index.aspx");

			}
		}
	}
}